<template>
  <div class="head">
    <div class="tit">
      <button id="1" :class="id === '1' ? 'active' : ''" class="tex1" @click="tab('1')">基本户账户交易明细</button>
      <button id="2" :class="id === '2' ? 'active' : ''" class="tex1" @click="tab('2')">代收货款账户交易明细</button>
      <button id="3" :class="id === '3' ? 'active' : ''" class="tex1" @click="tab('3')">基金账户交易明细</button>
    </div>
    <div class="line" />
    <div class="title">查询条件</div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form ref="form" style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;" :model="form" label-width="80px">
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1546px;">
              <el-form-item style="margin-left: 0;" class="text" label="网点编号">
                <el-input v-model="form.name" :disabled="true" class="input" placeholder="124000" />
              </el-form-item>
              <el-form-item class="text" label="网点名称">
                <el-select v-model="form.province" class="input" style="width: 228px;" :disabled="true" placeholder="辽宁省">
                  <el-option v-for="item in ProvinceList" :key="item.id" :label="item.province" :value="{ pid: item.pid, province: item.province }" />
                </el-select>
                <el-select v-model="form.city" class="input" :disabled="true" placeholder="盘锦市" style="width: 228px;margin-left: 12px;">
                  <el-option v-for="item in cityList" :key="item.id" :label="item.city" :value="item.city" />
                </el-select>
                <el-select v-model="form.networkName" :disabled="true" placeholder="辽宁盘锦公司" style="width: 228px;margin-left: 12px;">
                  <el-option v-for="item in cityList" :key="item.id" class="input" :label="item.city" :value="item.city" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="业务摘要">
                <el-input v-model="form.businessAbstract" class="input" />

              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="inquire">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form" style="display: flex;justify-content: space-between;flex-wrap: wrap;" :model="form" label-width="80px">
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1546px;">
              <el-form-item class="text" style="margin-left: 0;" label="交易金额">
                <el-input v-model="form.transactionAmount" class="input" />
              </el-form-item>
              <div>
                <el-select v-model="form.timeType" placeholder="请选择" style="width: 132px;">
                  <el-option label="业务日期" value="1" />
                  <el-option label="记账日期" value="2" />
                  <el-option label="报表业务日期" value="3" />
                </el-select>
                <el-date-picker v-model="value" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width: 644px;margin-left: 10px;" @change="changeTime" />
              </div>
              <el-form-item class="text" label="费用科目">
                <el-select v-model="form.hqCostSubjectId" class="input" placeholder="请选择" style="width: 286px;">
                  <el-option v-for="item in CostKindList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form" style="display: flex;flex-wrap: wrap;" :model="form">
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 812px;">
              <el-form-item v-if="id === '1' || id === '3'" class="text" style="display: flex;" label="费用科目收付类型">
                <el-select v-model="form.costSubjectType" class="input" placeholder="请选择" style="width: 286px;">
                  <el-option label="全部" value="0" />
                  <el-option label="总部应收" value="1" />
                  <el-option label="总部应付" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item v-if="id === '3'" class="text" style="display: flex;" label="业务类型">
                <el-select v-model="form.hqBusinessTypeId" class="input" placeholder="请选择" style="width: 286px;">
                  <el-option v-for="item in BusinessTypeList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item v-if="id === '1'" class="text" style="display: flex;" label="关联单号">
                <el-input v-model="form.relevanceCode" class="input" />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable v-if="id === '1'" v-loading="loading" :data="tableData" :th="th" :n="4">
          <template v-slot:before-columns>
            <el-table-column v-if="tableData.length>0" type="index" :index="indexMethod" width="50" />
          </template>

        </elltable>
        <elltable v-if="id === '2'" v-loading="loading" :data="tableData" :th="th" :n="4">
          <template v-slot:before-columns>
            <el-table-column v-if="tableData.length>0" type="index" :index="indexMethod" width="50" />
          </template>
        </elltable>
        <elltable v-if="id === '3'" v-loading="loading" :data="tableData" :th="th" :n="4">
          <template v-slot:before-columns>
            <el-table-column v-if="tableData.length>0" type="index" :index="indexMethod" width="50" />
          </template>
        </elltable>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <!-- <div class="title2">显示2到2，共2记录</div> -->
          <div class="title2" />
          <!-- <div class="title2">合计：29876</div> -->
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination background :current-page="current" :page-sizes="[10, 20, 30, 40]" :page-size="10" layout="total, prev, pager, next" :total="+total" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { BasicAccountApi, CostKindApi, BasicAccountApi1, BasicAccountApi2, BusinessTypeApi } from '@/api/HqFinancePanel'
import { getCityId, getProvinceList } from '@/api/dashboard'

export default {

  components: {},
  data() {
    return {
      loading: false,
      id: '1',
      ProvinceList: [], // 省
      cityList: [], // 市
      value: null,
      form: {
        name: '',
        networkName: '',
        province: '',
        city: '',
        businessAbstract: '',
        costSubjectType: '',
        endTime: '',
        hqBusinessTypeId: '',
        hqCostSubjectId: '',
        networkNameId: '辽宁盘锦公司',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        relevanceCode: '',
        startTime: '',
        timeType: '',
        transactionAmount: ''
      },
      mxForm: {
        destinationProvince: '',
        destinationCity: ''
      },
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      CostKindList: [], // 费用科目列表
      BusinessTypeList: [], // 业务类型列表
      th: []
    }
  },

  computed: {},

  created() {
    this.getProvince()
    this.CostKind()
    this.BusinessType()
  },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.inquire()
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.inquire()
    }, // 序号
    indexMethod(index) {
      return index * 1 + 1
    },
    // tab切换
    tab(e) {
      this.id = e
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate') {
          this.form[key] = ''
        }
        this.tableData = []
        this.value = []
        this.th = []
        this.total = 0
      })
    },
    // 获取省
    getProvince() {
      getProvinceList().then((res) => {
        if (res.code === 200) {
          this.ProvinceList = res.data
        }
      })
    },
    // 获取省的id
    provinceChange(value) {
      this.mxForm.destinationProvince = value.province
      this.getCity(value.pid)
    },
    getCity(pid) {
      getCityId(pid).then((res) => {
        if (res.code === 200) {
          this.cityList = res.data
        }
      })
    },
    // 选择时间
    changeTime() {
      if (this.value != null) {
        this.form.startTime = this.value[0]
        this.form.endTime = this.value[1]
      }
    },
    table(res) {
      this.tableData = res.data.list.data
      this.total = res.data.list.total
      this.current = res.data.list.current
      this.pages = res.data.list.pages
      this.th = res.data.fields
    },
    // 查询
    async inquire() {
      let res = null
      if (this.id === '1') {
        res = await BasicAccountApi(this.form)
      } else if (this.id === '2') {
        res = await BasicAccountApi1(this.form)
      } else if (this.id === '3') {
        res = await BasicAccountApi2(this.form)
      }
      this.loading = true
      if (res.code == 200) {
        this.table(res)
      }
      this.loading = false
    },
    // 费用科目列表
    async CostKind() {
      const res = await CostKindApi()
      this.CostKindList = res.data
    },
    // 业务类型列表
    async BusinessType() {
      const res = await BusinessTypeApi()
      this.BusinessTypeList = res.data
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
        this.tableData = []
        this.value = []
        this.total = 0
        this.current = 0
        this.pages = 0
      })
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: "";
    width: 142px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    // margin-left: 52px;
    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      // border: 1px solid #B4B4B4;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
